package be.kuleuven.peno3.mobiletoledo.view.queue;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import be.kuleuven.peno3.mobiletoledo.R;
import be.kuleuven.peno3.mobiletoledo.Data.Client.QueueClient;
import be.kuleuven.peno3.mobiletoledo.model.QueueInfo;

public class HistoryView extends Activity {
	private static final int[] COLORS = new int[] { 0xFF464646, 0xFF272727 };
	
	private LinearLayout container;
	
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.historyviewlayout);
		
		container = (LinearLayout) findViewById(R.id.historyviewlinearlayout);
		
		TextView bar = (TextView) findViewById(R.id.history_bar);
		bar.setText("Geschiedenis");
		
		String location = this.getIntent().getExtras().getString("location");
		TextView service = (TextView) findViewById(R.id.service);
		service.setText(location);
		service.setPadding(0, 5, 0, 0);
		

		QueueInfo[] qi = QueueClient.getLengthHistory(location);
		
		for(int i=0;i<qi.length;i++) {
			TextView t=new TextView(this);
			t.setText("Wachtrij van "+qi[i].getLength()+" personen");
			t.setBackgroundColor(COLORS[i%2]);
			t.setGravity(Gravity.LEFT);
			container.addView(t);
			t=new TextView(this);
			t.setBackgroundColor(COLORS[i%2]);
			t.setTextSize((float) 10);
			t.setGravity(Gravity.RIGHT);
			Calendar cal = qi[i].getCal();
			String min = "" + cal.get(Calendar.MINUTE);
			if(min.length() == 1){
				min = "0" + min;
			}
			t.setText(translateDay(cal.get(Calendar.DAY_OF_WEEK)) + " " + cal.get(Calendar.DATE)+"/"+(cal.get(Calendar.MONTH)+1)+" om "+cal.get(Calendar.HOUR_OF_DAY)+":"+min);
			container.addView(t);
		}
	}
	private String translateDay(int day){
		String[] days = new String [] {"", "Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"};
		return days[day];
	}
}
